<?php
$arr = array();
$loop = rand(20,30);
$loop = 10;

for($i=0;$i<=$loop;$i++){
	$sub_arr = array();
	$sub_loop = rand(5,7);
	for($j=1;$j<=$sub_loop;$j++){
		$sub_arr[] = $j;	
	}
	$arr[$i] = $sub_arr;
}
$array = array();
foreach($arr as $k=>$v){
	
	foreach($v as $k1=>$v1){
		$array[$k."__".$k1] = array("p"=>$k,$k1=>$v1);
	}
}
echo count($array)."<br/>";
echo intval(count($array)%3==0?count($array)/3:(count($array)/3+1));
print_r($array);
$chunk = array_chunk($array, 3);
print_r($chunk);